var originalFill;
var muted = "unmuted";
var playState = "stopped";
var sizeState = "small";

//--Play Button
function PlayMouseUp(sender,args)
{
    if (playState == "playing")
    {
        playState = "paused";
        mediaElement.Pause();
        togglePlayIcon(false);       
    }
    else {
        playMedia();
    }
}
function PlayMouseEnter(sender,args)
{   
     fadeInGlow.Begin();
     //playGlow.SetValue("Opacity", "1"); 
}   

function PlayMouseLeave(sender,args)
{ 
     fadeOutGlow.Begin();
     //playGlow.SetValue("Opacity", "0"); 
}
//--End Play Button
//--Stop Button
function StopMouseUp(sender,args)
{
    mediaElement.Stop(); 
    mediaElement.SetValue("Opacity", "0");
    mediaImage.SetValue("Opacity", "1");
    playState = "stopped";
    togglePlayIcon(false);
}
function StopMouseEnter(sender,args)
{
    stopBgd.SetValue("Opacity", "1");
}

function StopMouseLeave(sender,args)
{
    stopBgd.SetValue("Opacity", "0.01");
}
//-- End Stop Button
//-- Rewind Button
function RewindLeftButtonDown(sender,args)
{
     playState = "paused";
     mediaElement.Pause();
     speedModifier = -3;
}
function RewindMouseUp(sender,args)
{
     speedModifier = 0;
     playMedia();    
}
function RewindMouseEnter(sender,args)
{
    rewindGlow.SetValue("Opacity", "1");
}

function RewindMouseLeave(sender,args)
{
    rewindGlow.SetValue("Opacity", "0");
}
//-- End Rewind Button
//-- FForward Button
function FForwardLeftButtonDown(sender,args)
{
     playState = "paused";
     mediaElement.Pause();
     speedModifier = 3;
}
function FForwardMouseUp(sender,args)
{
     speedModifier = 0;
     playMedia();    
}
function FForwardMouseEnter(sender,args)
{
    fforwardGlow.SetValue("Opacity", "1");
}

function FForwardMouseLeave(sender,args)
{
    fforwardGlow.SetValue("Opacity", "0");
}
//-- End FForward Button
function PlayBackMouseEnter(sender,args)
{     
     playHead.SetValue("Opacity", "1");  
}

function PlayBackMouseLeave(sender,args)
{
    playHead.SetValue("Opacity", "0");  
}

function ReplayMouseUp(sender,args)
{
    var timeSlice = 3;
    var timeSpan = mediaElement.position;

    if(timeSpan.seconds > timeSlice)
        timeSpan.seconds = timeSpan.seconds - timeSlice;
    else
        timeSpan.seconds = 0;
    
    mediaElement.position = timeSpan;
}
//--Mute Button
function MuteMouseUp(sender,args)
{
    if (muted == "unmuted") {
        mediaElement.SetValue("IsMuted", 1);
        muted = "muted";
        mutedIcon.SetValue("Opacity", 1);
        audio1Icon.SetValue("Opacity", 0);
        audio2Icon.SetValue("Opacity", 0);
    }
    else {
        mediaElement.SetValue("IsMuted", 0);
        muted = "unmuted";
        mutedIcon.SetValue("Opacity", 0);
        audio1Icon.SetValue("Opacity", 1);
        audio2Icon.SetValue("Opacity", 1);
    }
}
function MuteMouseEnter(sender,args)
{
    muteBgd.SetValue("Opacity", "1");
}

function MuteMouseLeave(sender,args)
{
    muteBgd.SetValue("Opacity", "0.01");
}
//-- End Mute Button
//-- Resize Button
function ResizeMouseUp(sender,args)
{    
    if (sizeState == "small")
    {
        sizeState = "large";
        playerHost.style.width = "610px";
        playerHost.style.height = "525px";  
        root.SetValue("Clip", "F1 M 610.500000,520.500000 C 610.500000,523.261719 608.261719,525.500000 605.500000,525.500000 L 5.500000,525.500000 C 2.738770,525.500000 0.500000,523.261719 0.500000,520.500000 L 0.500000,5.500000 C 0.500000,2.738770 2.738770,0.500000 5.500000,0.500000 L 605.500000,0.500000 C 608.261719,0.500000 610.500000,2.738770 610.500000,5.500000 L 610.500000,520.500000 Z");
        root.SetValue("Width", "610");
        root.SetValue("Height", "525");        
        mediaScale.SetValue("ScaleX", "2");
        mediaScale.SetValue("ScaleY", "2");        
        mediaPlayback.SetValue("Canvas.Top", "454");
        playbackScale.SetValue("ScaleX", "2");
        mediaControls.SetValue("Canvas.Top", "467");
        mediaControls.SetValue("Canvas.Left", "156");
    }
    else
    {  
        sizeState = "small";
        playerHost.style.width = "310px";
        playerHost.style.height = "300px";
        root.SetValue("Clip", "F1 M 310.500000,292.500000 C 310.500000,296.917969 306.917969,300.500000 302.500000,300.500000 L 8.500000,300.500000 C 4.082031,300.500000 0.500000,296.917969 0.500000,292.500000 L 0.500000,8.500000 C 0.500000,4.081543 4.082031,0.500000 8.500000,0.500000 L 302.500000,0.500000 C 306.917969,0.500000 310.500000,4.081543 310.500000,8.500000 L 310.500000,292.500000 Z");
        root.SetValue("Width", "310");
        root.SetValue("Height", "300");
        mediaScale.SetValue("ScaleX", "1");
        mediaScale.SetValue("ScaleY", "1");
        mediaPlayback.SetValue("Canvas.Top", "229");
        playbackScale.SetValue("ScaleX", "1");
        mediaControls.SetValue("Canvas.Top", "242");
        mediaControls.SetValue("Canvas.Left", "6");
    }
}
function ResizeMouseEnter(sender,args)
{
    resizeBgd.SetValue("Opacity", "1");
}

function ResizeMouseLeave(sender,args)
{
    resizeBgd.SetValue("Opacity", "0.01");
}
//-- End Resize Button
// ---- helper
function playMedia()
{
     if(mediaElement.GetValue("Source") == undefined)
          mediaElement.SetValue("Source", currentMedia);            

     mediaElement.SetValue("Opacity", "1");
     mediaImage.SetValue("Opacity", "0");
     mediaElement.Play();
     playState = "playing";        

     togglePlayIcon(true);
}

function togglePlayIcon(playing)
{
     if(playing)
     {
          pauseIcon.SetValue("Opacity", 1);
          playIcon.SetValue("Opacity", 0);
     }
     else
     {
          pauseIcon.SetValue("Opacity", 0);
          playIcon.SetValue("Opacity", 1);
     }    
}
function toggleCursor(overButton)
{
     if(overButton)
          playerHost.style.cursor = 'pointer';
     else
          playerHost.style.cursor = 'default';
}